package com.ybkj.daijia.aop;

import com.ybkj.daijia.serverUtils.SettingUtils;
import java.net.MalformedURLException;
import java.net.URL;
import javax.servlet.http.HttpServletRequest;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

/***
 * 没啥用 zhyu 注掉
 */
//@Aspect
//@Component
public class ServerControllerAop {

    private static final Logger logger = LoggerFactory.getLogger(ServerControllerAop.class);

    @Autowired
    private SettingUtils settingUtils;

    public static void main(String[] args) throws MalformedURLException {
        String referer = "http://39.106.66.75:81/";
        URL url = new URL(referer);
        String host = url.getHost();
        System.out.println(host);
        String web = "http://39.106.66.75:81/";
        System.out.println(web.indexOf(host));
    }

    @Pointcut("execution(public * com.ybkj.daijia.server.controller.*.*(..))")
    public void postcomitInterceptionController() {

    }

    @Around("postcomitInterceptionController()")
    public Object PostcomitController(ProceedingJoinPoint thisJoinPoint) throws Throwable {
        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder
            .getRequestAttributes()).getRequest();
        String referer = request.getHeader("Referer");

        Object result = thisJoinPoint.proceed();
        return result;
    }
}